/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.terminalrodoviario;

import java.util.Collection;
import java.util.Date;

/**
 *
 * @author jorge
 */
public class Company extends BaseEntity<Company>{

    // <editor-fold defaultstate="collapsed" desc="Builders">
    public Company()
    {
    }
    public Company(String name, String email, String corporateName, String municipalRegistration, String stateRegistration, String address, String cep, String description, String phone, String fax, City city, Date dateFundation, String webSite, Date insertDate, String logo, String cnpj)
    {
        this.city=city;
        this.address=address;
        this.cep=cep;
        this.corporateName=corporateName;
        this.dateFundation=dateFundation;
        this.description=description;
        this.email=email;
        this.fax=fax;
        this.insertDate=insertDate;
        this.logo=logo;
        this.municipalRegistration=municipalRegistration;
        this.name=name;
        this.phone=phone;
        this.stateRegistration=stateRegistration;
        this.webSite=webSite;
        this.cnpj=cnpj;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Properties">
    private String name;
    private String email;
    private String cnpj;
    private String corporateName;
    private String municipalRegistration;
    private String stateRegistration;
    private String address;
    private String cep;
    private String description;
    private String phone;
    private String fax;
    private City city;
    private Date dateFundation;
    private String webSite;
    private Date insertDate;
    private String login;
    private String password;
    private String logo;

    // </editor-fold>   

    // <editor-fold defaultstate="collapsed" desc="Gets and Sets">
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCorporateName() {
        return corporateName;
    }

    public void setCorporateName(String corporateName) {
        this.corporateName = corporateName;
    }

    public String getMunicipalRegistration() {
        return municipalRegistration;
    }

    public void setMunicipalRegistration(String municipalRegistration) {
        this.municipalRegistration = municipalRegistration;
    }

    public String getStateRegistration() {
        return stateRegistration;
    }

    public void setStateRegistration(String stateRegistration) {
        this.stateRegistration = stateRegistration;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCep() {
        return cep;
    }

    public void setCep(String cep) {
        this.cep = cep;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }    

    public Date getDateFundation() {
        return dateFundation;
    }

    public void setDateFundation(Date dateFundation) {
        this.dateFundation = dateFundation;
    }

    public String getWebSite() {
        return webSite;
    }

    public void setWebSite(String webSite) {
        this.webSite = webSite;
    }

    public Date getInsertDate() {
        return insertDate;
    }

    public void setInsertDate(Date insertDate) {
        this.insertDate = insertDate;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }
     public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the cnpj
     */
    public String getCnpj() {
        return cnpj;
    }

    /**
     * @param cnpj the cnpj to set
     */
    public void setCnpj(String cnpj) {
        this.cnpj = cnpj;
    }
    // </editor-fold>

    public Company authenticate(String login, String pwd){
        Encryption e = new Encryption();
        Collection<Company> companies = new Company().select("Select c from Company c where c.login='"+login+"'");
        for (Company u : companies)
            if (u.getPassword().equals(e.encrypt(pwd)))
                return u;
        return null;
    }

}